package main

import "fmt"

func main() {
	d := New()
	d.SetArgs([]string{})
	err := d.Run()
	if err != nil {
		panic(err)
	}

	//fmt.Println("----> wait")
	for {
		var input string
		fmt.Printf("please input: ")
		fmt.Scan(&input)

		sw := input
		//		fmt.Println("main, in:", input)
		recv, errw := d.Send(sw)
		if errw != nil {
			fmt.Println("错误退出，", errw)
			return
		}
		fmt.Println("main, ou:", recv)
	}

	//sw := input + "\n"
	//bytWrite := []byte(sw)
	//nw, err_write := stdin.Write(bytWrite)
	//if err_write != nil {
	//panic(err_write)
	//}
	//fmt.Printf("[stdin] n=%v, send: %v\n", nw, sw)
	////	time.Sleep(10 * time.Millisecond)
	//}

	//fmt.Println("vim-go")
	//// pipeReader, pipeWriter := io.Pipe()

	//binPath := "../03-ncpk-nvm/nvm"
	//binArgs := []string{
	//"-debug",
	//"true",
	////"--file",
	////"./resource/script000-debug.nsmb",
	////"--contrl",
	////"./resource/000-uc-control.json",
	////"--param",
	////"./resource/000-uc-param.json",
	//}

	//// 进程绑定输入和输出到管道
	//process := exec.Command(binPath, binArgs...)

	////process.Stdout = pipeWriter
	////process.Stdin = pipeReader
	//stdin, err := process.StdinPipe()
	//if err != nil {
	//panic(err)
	//}
	//stdout, err := process.StdoutPipe()
	//if err != nil {
	//panic(err)
	//}
	//stderr, err := process.StderrPipe()
	//if err != nil {
	//panic(err)
	//}

	//chQuit := make(chan int)
	//go func(ch chan int) {
	//for {
	//bytBuf := make([]byte, 1024)
	//n, err_read := stderr.Read(bytBuf)
	//if err_read != nil {
	//if err_read == io.EOF {
	//fmt.Printf("[stderr] eof, n=%v\n", n)
	//ch <- 1
	//return
	//} else {
	//panic(err_read)
	//}
	//}
	//fmt.Printf("[stderr] n=%v, recv:\n%v\n", n, string(bytBuf))
	//}
	//}(chQuit)

	//go func() {
	//for {
	//bytBuf := make([]byte, 1024)
	//fmt.Println("[stdout] wait")
	//n, err_read := stdout.Read(bytBuf)
	//if err_read != nil {
	//panic(err_read)
	//}
	//fmt.Printf("[stdout] n=%v, recv:\n%v\n", n, string(bytBuf))
	//}
	//}()
	//err = process.Start()
	//if err != nil {
	//panic(err)
	//}

	//for {
	//var input string
	//fmt.Scan(&input)

	//sw := input + "\n"
	//bytWrite := []byte(sw)
	//nw, err_write := stdin.Write(bytWrite)
	//if err_write != nil {
	//panic(err_write)
	//}
	//fmt.Printf("[stdin] n=%v, send: %v\n", nw, sw)
	////	time.Sleep(10 * time.Millisecond)
	//}

	//<-chQuit

	//select {}
}
